package serv;

import com.alibaba.fastjson.JSON;
import mapper.DataMapper;
import util.Tmp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/findMore")
public class FindMore extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("findMore");
        String sql="select msg,keyword from t_data where keyword like ? or msg like ?";
        List list=null;
        String key=req.getParameter("key");
        try {
            list= Tmp.query(sql,new DataMapper(),"%"+key+"%","%"+key+"%");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        String msg= JSON.toJSONString(list);
        resp.getWriter().print(msg);
    }
}
